path <-
"/Users/robert/ab-1279/Alameda/Parcels-shp/"
alameda_county_parcel_data <-
read_sf(path)
Constants
QUARTER_ACRE <-
10890 # SQUARE FEET
HALF_ACRE <-
21780 # SQUARE FEET
NONZERO_PARCEL_SIZE_COUNT_UNIQUE_APN_SORT <-
97474
access_token <-
"pk.eyJ1Ijoicm9iZXJ0c3ByYWdnIiwiYSI6ImNqd2NtNjh0YzBiNzMzenBsNDl3cXQ1em8ifQ.1d2QhIjr8R8ZUlzjwcYx9w"
style_oakland_map <-
"mapbox://styles/robertspragg/ckce9o0fi09vb1ipdrpo41iq8"
Load the Alameda County Parcel shapefile, select metadata of interest, and transform coordinates.
parcels_geom_only <-
alameda_county_parcel_data %>%
select(geometry, APN_SORT, OBJECTID, LotSize, SitusAddre) %>%
st_transform(crs = 4326)
To find the Oakland parcels of interest, first load the Alameda County shapefile, remove the geometry to speed things up, and filter for all Oakland parcels.
parcels_no_geometry <-
alameda_county_parcel_data %>%
st_drop_geometry()
oakland_parcels <-
parcels_no_geometry %>%
filter(SitusCity == "OAKLAND")
Next, let’s find the number of Oakland parcels larger than a quarter acre (10890 square feet)
oakland_parcels %>%
group_by(APN_SORT) %>%
slice(1) %>% # 98,294
filter(LotSize > 0) %>% # 97,474
filter(LotSize > QUARTER_ACRE) %>%
nrow()
## [1] 10723
Let’s repeat this for parcels greater than half an acre.
oakland_parcels %>%
group_by(APN_SORT) %>%
slice(1) %>% # 98,294
filter(LotSize > 0) %>% # 97,474
filter(LotSize > HALF_ACRE) %>%
nrow()
## [1] 4245
There are 10,723 parcels greater than a quarter acre, and 4,245 greater than a quarter acre. Now, let’s save the lists of these parcels.
parcel_list_half_acre <-
oakland_parcels %>%
group_by(APN_SORT) %>%
slice(1) %>% # 98,294
filter(LotSize > 0) %>% # 97,474
filter(LotSize > HALF_ACRE) %>%
select(APN_SORT, LotSize) %>%
select(APN_SORT) %>% pull
parcel_list_quarter_acre <-
oakland_parcels %>%
group_by(APN_SORT) %>%
slice(1) %>% # 98,294
filter(LotSize > 0) %>% # 97,474
filter(LotSize > QUARTER_ACRE) %>%
select(APN_SORT, LotSize) %>%
select(APN_SORT) %>% pull
Finally, using our original shapefile data, let’s plot the parcels whose APNs are in the list of parcels greater than half an acre in size.
leaflet(parcels_geom_only %>% filter(APN_SORT %in% parcel_list_half_acre)) %>%
addMapboxGL(
accessToken = access_token,
style = style_oakland_map
) %>%
addPolygons(color = "#444444", weight = 1, smoothFactor = 0.5,
opacity = 1.0, fillOpacity = 0.5,
fillColor = ~colorQuantile("YlOrRd", LotSize)(LotSize),
label = ~SitusAddre,
highlightOptions = highlightOptions(color = "white", weight = 2,
bringToFront = TRUE))